package com.cndw.kungfu.model.goods.domain;

import java.util.Comparator;

import com.cndw.kungfu.domain.Goods;

/**
 * 背包物品排序函数
 * @author fantadust [9677889@qq.com]
 * @date 2011-6-22 下午03:49:53
 */
public class GoodsComparator implements Comparator<Goods> {

	@Override
	public int compare(Goods arg0, Goods arg1) {
		
		int exp = arg0.getGoodsId() - arg1.getGoodsId() ;
		
		if ( exp <0 ) {
			return -1;
		}else if ( exp > 0 ) {
			return 1;
		}else {
			if (arg0.getBinding() > arg1.getBinding()) {
				return -1;
			}else if (arg0.getBinding() < arg1.getBinding()) {
				return 1;				
			}
			
			if (arg0.getStackNum() > arg1.getStackNum() ) {
				return 1;
			}else if (arg0.getStackNum() < arg1.getStackNum()) {
				return -1;
			}else {				
				if (arg0.getId() > arg1.getId() ) {
					return 1;
				}else if (arg0.getId() < arg1.getId()) {
					return -1;
				}else {
					if (arg0.getCreateTime() > arg1.getCreateTime() ) {
						return 1;
					}else if (arg0.getCreateTime() < arg1.getCreateTime()) {
						return -1;
					}
					return arg0.hashCode() - arg1.hashCode();
				}				
			}
			
			
		}
		
	}

}
